package com.example.administrator.xiaoxiang.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.administrator.xiaoxiang.R;
import com.example.administrator.xiaoxiang.activity.HomeSecondActivity;
import com.example.administrator.xiaoxiang.bean.HomeHotBannerItemBean;

import java.util.List;

/**
 * Created by Administrator on 2017/1/6.
 * 这是热点的Adapter（RecyclerView）
 */

public class HomeHotAdapter extends RecyclerView.Adapter<HomeHotAdapter.MyViewHolder> {


    private Context context;
    private List<HomeHotBannerItemBean> data;
    public HomeHotAdapter(Context context, List<HomeHotBannerItemBean> data) {
        this.context = context;
        this.data = data;
//        Log.e(TAG, "HomeHotAdapter: "+data.size());
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_hot_recyclerview,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
//        Log.e(TAG, "onBindViewHolder: "+data.get(position).smallImageUrl );

        Glide.with(context).load(data.get(position).smallImageUrl).placeholder(R.drawable.home_image_hot_bitmap).into(holder.imageView);
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, HomeSecondActivity.class);
                intent.putExtra("secondUrl",data.get(position).secondurl+".json");
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        public MyViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.imageView_hot_recyclerView);
        }
    }
}
